﻿function $$(domId){return document.getElementById(domId);}
function $$A(domName){return document.getElementsByName(domName);}
function $$a(domName){return document.getElementsByName(domName)[0];}
function $$T(tagName){return document.getElementsByTagName(tagName);}
String.prototype.trim=function(){return this.replace(/^\s*|\s*$/g,'');}
Array.prototype.remove=function(item){
	for(var i=this.length-1;i>=0;i--){
		if(this[i]==item) this.splice(i,1);
	}
}
Array.prototype.removeAt=function(i){
    this.splice(i,1);
}
Array.prototype.indexOf=function(item){
	for(var i=0;i<this.length;i++){
		if(this[i]==item) return i;
	}
	return -1;
}
//注册名称空间
Function.registerNameSpace=function(spaceValue){
	var values=spaceValue.split(".");
	var obj=window;
	for(var i=0;i<values.length;i++){
		if(!obj[values[i]]) obj[values[i]]=new Object();
		obj=obj[values[i]];
	}
}
//js包根目录
/*
Function._____basePath=(function(){
    var scripts=document.getElementsByTagName("script");
    var o=scripts[scripts.length-1];
    var src=o.src.toString();
    return src.substring(0,src.lastIndexOf("/"));
})();
*/
//加载js
//AGuang文件夹根目录用#/
Function.using=function(path,charset){
    if(path.indexOf("#/")==0){//脚本项目里的代码
        path=path.replace("#",Function._____basePath);
    }
    var script=document.createElement("script");
    if(charset) script.charset=charset;
    script.src=path;
    script.id=path;
    var heads=document.getElementsByTagName("head");
    heads[0].insertBefore(script,heads[0].childNodes[0]);
}
//显示时间,已过时，请用Date.js中的showTime
Function.showTime=function(obj){
    var date=new Date();
    var year=date.getFullYear();
    var month=date.getMonth()+1;
    var day=date.getDate();
    var minute=date.getMinutes();
    var second=date.getSeconds();
    var house=date.getHours();
    var m=Function.formatInt(month,2);
    var d=Function.formatInt(day,2);
    var h=Function.formatInt(house,2);
    var mi=Function.formatInt(minute,2);
    var s=Function.formatInt(second,2);
    obj.innerHTML=year.toString()+"年"+m+"月"+d+"日 "+h+":"+mi+":"+s;
    setTimeout(function(){Function.showTime(obj)},500);
}
Function.formatInt=function(num,len){
    var n=num.toString();
    var l=(len-n.length);
    if(l>0){
        var pre="";
        for(var i=0;i<l;i++){
            pre+="0";
        }
        return pre+n;
    }
    return n;
}

//浏览器判断
document.IsIE=document.all&&true;
document.IsIE6=document.IsIE&!window.XMLHttpRequest;

//FF属性兼容
(function(bool){
    if(bool){
        HTMLElement.prototype.__defineGetter__("innerText",function(){
            return this.textContent;
        });
        HTMLElement.prototype.__defineSetter__("innerText",function(s){
            this.textContent=s;
        });
        HTMLElement.prototype.__defineGetter__("currentStyle",function () { 
            return this.ownerDocument.defaultView.getComputedStyle(this,null); 
        });
        HTMLElement.prototype.__defineGetter__("outerHTML",function() {
            var a=this.attributes, str="<"+this.tagName, i=0;for(;i<a.length;i++)
            if(a[i].specified)
            str+=" "+a[i].name+'="'+a[i].value+'"';
            if(!this.canHaveChildren)
            return str+" />";
            return str+">"+this.innerHTML+"</"+this.tagName+">";
        });
        HTMLElement.prototype.__defineSetter__("outerHTML",function(s){
            var r = this.ownerDocument.createRange();
            r.setStartBefore(this);
            var df = r.createContextualFragment(s);
            this.parentNode.replaceChild(df, this);
            return s;
        });
        HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
            switch(this.tagName.toLowerCase()){
                case "area":
                case "base":
                case "basefont":
                case "col":
                case "frame":
                case "hr":
                case "img":
                case "br":
                case "input":
                case "isindex":
                case "link":
                case "meta":
                case "param":
                    return false;
            }
            return true;
        });
    }
})(!document.IsIE);
